program heapsorting;

{$APPTYPE CONSOLE}
var
a : array of integer;
n : integer;
i : integer;
procedure sift(L, R : integer);
var i, j, x : integer;
begin
  i:=L;
  j:= 2*i+1;
  x := a[i];
  if (j<R) and (a[j]<a[j+1]) then j:=j+1;
  while (j<=R) and (x < a[j]) do
  begin
    a[i] := a[j];
    i := j;
    j := 2*j + 1;
    if (j<R) and (a[j]<a[j+1]) then j:=j+1;
  end;
  a[i] := x;
end;
procedure makeheap;
var L : integer;
begin
  L := n div 2;
  while L>0 do
  begin
    L := L-1;
    sift(l, n-1);
  end;
end;
procedure heapsort;
var L, R, temp : integer;
begin
  makeheap;
  L := 0;
  R := n-1;
  while R>0 do
  begin
    temp := a[0];
    a[0] := a[R];
    a[R] := temp;
    R := R-1;
    sift(L, R);
  end;
end;
begin
  readln(n);
  setlength(a, n);
  for i:=0 to n-1 do
    read(a[i]);
  heapsort;
  for i:=0 to n-1 do
    write(a[i],' ');
  readln;
end.
 